<?php defined('SYSPATH') or die('No direct access allowed.');

//动态码
class Controller_Pc_Api_V2_Dynamic extends Controller_Pc_Api_v2_Base
{
    // 参数验证对象
    /**
     * @var Request_Api_V2_Dynamic
     */
    private $validation;

    /**
     * @var Service_Api_Dynamic
     */
    private $service;

    public function before()
    {
        parent::before();

        // 返回数据
        $this->result = array('status' => true, 'msg' => '操作成功', 'data' => array());

        // 验证
        $this->validation = Request_Api_V2_Factory::create('dynamic', $this->request_params);
        $this->service = new Service_Api_Dynamic();

    }
    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    //动态
    public function action_code()
    {
        try{
            $this->validation->code()->check();
            $rtn = $this->service->code($this->request_params);
            if ($rtn['status']) {
                $this->result['status'] = true;
                $this->result['msg'] ='发送成功';
            } else {
                $this->result['status'] = false;
                $this->result['msg'] = $rtn['msg'];
            }
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }
}
